<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/3
 * Time: 17:31
 */

namespace App\Http\Controllers;

use App\Http\Logics\CommonLogic;
use App\Http\Traits\CommonTrait;
class CommonController extends BaseController
{
    use CommonTrait;

    /**
     * @SWG\GET(
     *     path="/common/createReusableSignature",
     *     tags={"Common"},
     *     description="获取COS上传可重复使用的签名",
     *     operationId="createReusableSignature",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=false,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="bucket",
     *         in="query",
     *         description="COS上的bucket",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="region",
     *         in="query",
     *         description="COS区域",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createReusableSignature()
    {

        $bucket = $this->bucket;
        $region = $this->region;
        $data = [
            'bucket' => $bucket,
            'region' => $region
        ];
        $response = CommonLogic::createReusableSignature($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }


    public function callback()
    {
        $cover_url = $this->cover_url;
        $height = $this->height;
        $width = $this->width;
        $data = [
            'cover_url' => $cover_url,
            'height' => $height,
            'width' => $width
        ];
        $response = CommonLogic::callback($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\GET(
     *     path="/common/getImageInfo",
     *     tags={"Common"},
     *     description="获取图片信息",
     *     operationId="getImageInfo",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="url",
     *         in="query",
     *         description="链接地址",
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getImageInfo()
    {
        $url = $this->url;
        $data = [
            'url' => $url
        ];
        $response = CommonLogic::getImageInfo($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}